package com.zhumr.util;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;

/**
 * 爬虫
 * 
 * @author HP
 *
 */
public class WebSpider {

	public static void main(String[] args) {
		// 相当于打开浏览器
		HttpClient httpClient = new HttpClient();
		// 输入网址
		GetMethod getMethod = new GetMethod("http://www.iqiyi.com/");

		try {
			int statusCode = httpClient.executeMethod(getMethod);
			System.out.println("statusCode=" + statusCode);
			System.out.println("response= " + getMethod.getResponseBodyAsString());

		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			// 关闭连接
			getMethod.releaseConnection();
		}

	}

}
